/*
 * @Description: 鉴定与处置Reducer
 * @Author: Zzt
 * @Date: 2022-08-09 14:59:01
 * @LastEditTime: 2022-08-15 09:36:15
 */

import {
  SET_SELECTED_ITEM,
  ADD_PLAN,
  DELETE_PLAN_ITEM,
  APPROVAL,
  SET_PLAN_LIST
} from '../constants';
import { delItemByIdArray, editItemById, insertItem } from '@/utils/list';

export const AppraisalAndDispositionReducer = (state, action) => {
  switch (action.type) {
    // 获取表数据
    case SET_PLAN_LIST:
      return {
        ...state,
        plan: action.data
      };
    // 新增计划
    case ADD_PLAN: {
      return {
        ...state,
        plan: insertItem(action.data, state.plan)
      };
    }
    /**
     * @description: 删除表格选中的条目id
     * @param {number[]} data
     */
    case SET_SELECTED_ITEM:
      return { ...state, delId: action.data };
    case DELETE_PLAN_ITEM: {
      console.log('del_export', action.ids);
      return {
        ...state,
        plan: delItemByIdArray(action.ids, state.plan)
      };
    }
    // // 被选中修改的
    // case SELECT_PLAN:
    //   console.log(action.data);
    //   // eslint-disable-next-line no-case-declarations
    //   return {
    //     ...state,
    //     select: action.data,
    //     isVisible: true
    //   };
    // // 窗口可视
    // case EDIT_PLAN:
    //   return {
    //     ...state,
    //     // select: {},
    //     isVisible: action.data
    //   };
    // // 修改
    // case APPROVAL:
    //   console.log(action.data);
    //   return {
    //     ...state,
    //     plan: editItemById(action.data.id, action.data, state.plan)
    //   };
    case APPROVAL: {
      // const ToDo = JSON.parse(JSON.stringify(state.List));
      console.log('TODO', state.plan);
      return {
        ...state,
        plan: editItemById(action.data.id, action.data, state.plan)
      };
    }
    default:
      console.log('untouched', action);
      return state;
  }
};
